import Vue from 'vue'
import VueRouter from 'vue-router'

// +登录
import Login from '../pages/Login.vue'

// +布局
import Admin from '../views/Admin.vue'

// +系统首页------
// -经营概况
import Home from '../views/home/Home.vue'
// -预约记录
import AppointmentRecord from '../views/home/AppointmentRecord.vue'
// -教练签到
import CoachSign from '../views/home/CoachSign.vue'
// -预约记录2
import RecordTable from '../views/home/RecordTable.vue'
// -账号资料
import Account from '../views/home/Account.vue'
//------

// +用户管理------
// - 会员列表大框
import MemberA from '../views/user/MemberA.vue'
// -会员等级大框
import MemberB from '../views/user/MemberB.vue'
// -会员卡大框
import MemberC from '../views/user/MemberC.vue'
// -教练大框
import MemberD from '../views/user/MemberD.vue'

// -会员列表
import MemberList from '../views/user/MemberList.vue'
// -会员等级
import MemberGarde from '../views/user/MemberGarde.vue'

import MemberCardAdd from '../views/user/MemberCardAdd.vue'
// -会员卡
import MemberCard from '../views/user/MemberCard.vue'
// -教练列表
import CoachList from '../views/user/CoachList.vue'
// -会员列表修改
import MemberListEditor from '../views/user/MemberListEditor.vue'
// -会员添加
import MemberListAdd from '../views/user/MemberListAdd.vue'
// -会员查看
import MemberListLook from '../views/user/MemberListLook.vue'
// -教练添加
import CoachListAdd from '../views/user/CoachListAdd.vue'
// -教练查看
import CoachListLook from '../views/user/CoachListLook.vue'
// -教练修改
import CoachListEditor from '../views/user/CoachListEditor.vue'
//------

// +系统管理------
// -成员管理
import MemberAdmin from '../views/system/MemberAdmin.vue'
// -成员添加
import MemberAddition from '../views/system/MemberAddition.vue'
// -成员编辑
import MemberEditing from '../views/system/MemberEditing.vue'
// -角色管理
import Character from '../views/system/Character.vue'
// -角色权限设置
import RolePermissions from '../views/system/RolePermissions.vue'
// -广告管理
import Advertising from '../views/system/Advertising.vue'
// -广告编辑
import AdvertisingEditor from '../views/system/AdvertisingEditor.vue'
// -广告添加
import AdvertisementAddition from '../views/system/AdvertisementAddition.vue'
import Announcement from '../views/system/Announcement.vue'
import System from '../views/system/System.vue'
//------

// +商城管理------
import ProductList from '../views/shop/ProductList.vue'
import ProductCategory from '../views/shop/ProductCategory.vue'
import ProductOrder from '../views/shop/ProductOrder.vue'
import AddProduct from '../views/shop/AddProduct.vue'
import ProductEdit from '../views/shop/ProductEdit.vue'
import ProcessingOrderst from '../views/shop/ProcessingOrderst.vue'
import OrderUserDetails from '../views/shop/OrderUserDetails.vue'
//------

// +课程管理------
// -团课管理
import League from '../views/course/league/League.vue'
// -团课课程
import Leaguecourse from '../views/course/league/Leaguecourse.vue'
// -团课课表
import Leagueclass from '../views/course/league/Leagueclass.vue'
// -会员卡页面
import Vip from '../views/course/league/Vip.vue'
// -添加团课
import Addleague from '../views/course/league/Addleague.vue'
// -私教管理
import Personal from '../views/course/personal/Personal.vue'
// -添加私教
import Addpersonal from '../views/course/personal/Addpersonal.vue'
// -评价管理
import Commenton from '../views/course/commenton/Commenton.vue'
//------

// +场馆管理------
// -场馆列表
import Venue from '@/views/venue/Venue.vue'
// -添加场馆
import Addvenue from '../views/venue/Addvenue.vue'
// -编辑场馆
import Editvenue from '../views/venue/Editvenue.vue'
//------

// +活动管理------
// -优惠券
import Discount from '../views/active/Discount.vue'
// -添加优惠券
import Adddiscount from '../views/active/Adddiscount.vue'
// -编辑优惠券
import Editcount from '../views/active/Editcount.vue'
//------


Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'Admin',
    component: Admin,
    redirect: '/login',
    children: [

      //系统首页------
      {
        path: 'home',
        name: 'Home',
        component: Home,
      },
      {
        path: 'appointmentrecord',
        name: 'AppointmentRecord',
        component: AppointmentRecord
      },
      {
        path: 'coachsign',
        name: 'CoachSign',
        component: CoachSign
      },
      {
        path: 'recordtable',
        name: 'RecordTable',
        component: RecordTable
      },
      {
        path: 'account',
        name: 'Account',
        component: Account
      },
      //------

      //用户管理------
      {
        path: 'membera',
        name: 'MemberA',
        component: MemberA,
        redirect: '/membera/memberlist',
        children: [
          {
            path: 'memberlist',
            name: 'MemberList',
            component: MemberList
          },
          {
            path: 'memberlisteditor',
            name: 'MemberListEditor',
            component: MemberListEditor
          },
          {
            path: 'memberlistlook',
            name: 'MemberListLook',
            component: MemberListLook
          },
          {
            path: 'memberlistadd',
            name: 'MemberListAdd',
            component: MemberListAdd
          },
        ]
      },
      {
        path: 'memberb',
        name: 'MemberB',
        component: MemberB,
        redirect: '/memberb/membergarde',
        children: [
          {
            path: 'membergarde',
            name: 'MemberGarde',
            component: MemberGarde
          },
        ]
      },
      {
        path: 'Memberc',
        name: 'MemberC',
        component: MemberC,
        redirect: '/memberc/membercard',
        children: [
          {
            path: 'membercard',
            name: 'MemberCard',
            component: MemberCard
          },
          {
            path: 'membercardadd',
            name: 'MemberCardAdd',
            component: MemberCardAdd
          },
        ]
      },
      {
        path: 'memberd',
        name: 'MemberD',
        component: MemberD,
        redirect: '/memberd/coachlist',
        children: [
          {
            path: 'coachlist',
            name: 'CoachList',
            component: CoachList
          },
          {
            path: 'coachlistadd',
            name: 'CoachListAdd',
            component: CoachListAdd
          },
          {
            path: 'coachlisteditor',
            name: 'CoachListEditor',
            component: CoachListEditor
          },
          {
            path: 'coachlistlook',
            name: 'CoachListLook',
            component: CoachListLook
          }
        ]
      },
      //------

      //系统管理------
      // 成员管理
      {
        path: 'memberadmin',
        name: 'MemberAdmin',
        component: MemberAdmin,
      },
      // 成员添加
      {
        path: 'memberaddition',
        name: 'MemberAddition',
        component: MemberAddition
      },
      // 成员编辑
      {
        path: 'memberediting',
        name: 'MemberEditing',
        component: MemberEditing
      },
      // 角色管理
      {
        path: 'character',
        name: 'Character',
        component: Character,
      },
      // 角色权限设置
      {
        path: 'rolepermissions',
        name: 'RolePermissions',
        component: RolePermissions
      },
      // 广告管理
      {
        path: 'advertising',
        name: 'Advertising',
        component: Advertising,
      },
      // 广告编辑
      {
        path: 'advertisingeditor',
        name: 'AdvertisingEditor',
        component: AdvertisingEditor
      },
      // 广告添加
      {
        path: 'advertisementaddition',
        name: 'AdvertisementAddition',
        component: AdvertisementAddition
      },
      {
        path: 'announcement',
        name: 'Announcement',
        component: Announcement
      },
      {
        path: 'system',
        name: 'System',
        component: System
      },
      //------



      //商城管理------
      {
        path: 'productlist',
        name: 'ProductList',
        component: ProductList
      },
      {
        path: 'productcategory',
        name: 'ProductCategory',
        component: ProductCategory
      },
      {
        path: 'productorder',
        name: 'ProductOrder',
        component: ProductOrder
      },
      //商品列表添加
      {
        path: 'addproduct',
        name: 'AddProduct',
        component: AddProduct
      },
      //商品列表编辑
      {
        path: 'productedit',
        name: 'ProductEdit',
        component: ProductEdit
      },
      //订单处理
      {
        path: 'processingorderst',
        name: 'ProcessingOrderst',
        component: ProcessingOrderst
      },
      //订单用户信息
      {
        path: 'orderUserdetails',
        name: 'OrderUserDetails',
        component: OrderUserDetails
      },
      //------

      //课程管理------
      {
        path: 'league',
        name: 'League',
        component: League,
        redirect: '/league/leaguecourse',
        children: [
          {
            path: 'leaguecourse',
            name: 'Leaguecourse',
            component: Leaguecourse
          },
          {
            path: 'leagueclass',
            name: 'Leagueclass',
            component: Leagueclass
          }
        ]
      },
      {
        path: 'vip',
        name: 'Vip',
        component: Vip
      },
      {
        path: 'addleague',
        name: 'Addleague',
        component: Addleague
      },
      {
        path: 'personal',
        name: 'Personal',
        component: Personal
      },
      {
        path: 'addpersonal',
        name: 'Addpersonal',
        component: Addpersonal
      },
      {
        path: 'commenton',
        name: 'Commenton',
        component: Commenton
      },
      //------

      //场馆管理------
      {
        path:'venue',
        name:'Venue',
        component:Venue
      },
      {
        path:'addvenue',
        name:'Addvenue',
        component:Addvenue
      },
      {
        path:'editvenue',
        name:'editvenue',
        component:Editvenue
      },
      //------
      
      //活动管理------
      {
        path:'discount',
        name:'Discount',
        component:Discount
      }, 
      {
        path:'adddiscount',
        name:'Adddiscount',
        component:Adddiscount
      }, 
      {
        path:'editcount',
        name:'Editcount',
        component:Editcount
      }, 
      //------
    ]
  },

  //登录
  {
    path: '/login',
    name: 'Login',
    component: Login,
  },

]

const router = new VueRouter({
  routes
})

router.beforeEach((to, from, next) => {
  if (to.path === '/login') {
    next();
  } else {
    let token = sessionStorage.getItem('token');

    if (token === null || token === '') {
      next('/login');
    } else {
      next();
    }
  }
});

export default router
